fishbowl: Don't show ridiculous precision
authorMatthias Clasen <mclasen@redhat.com>
Thu, 23 May 2019 12:37:47 +0000 (12:37 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 23 May 2019 12:38:57 +0000 (12:38 +0000)
Two decimals are more than enough for the frame rate.

demos/gtk-demo/fishbowl.ui
demos/gtk-demo/gtkfishbowl.c

index c6216666b634c388a9033985222470a1ecba63d9..34136b294665528d668c4795ded54ee00725a239 100644 (file)
@@ -31,7 +31,7 @@
         </child>
         <child type="end">
           <object class="GtkLabel">
-            <property name="label" bind-source="bowl" bind-property="framerate"/>
+            <property name="label" bind-source="bowl" bind-property="framerate-string"/>
           </object>
         </child>
         <child type="end">
index 5cfbcf83fcd23990d9d0781dff10023c8756db76..1711d91376b73492493ff562f38c10a8d9f4ce15 100644 (file)
@@ -53,6 +53,7 @@ enum {
    PROP_BENCHMARK,
    PROP_COUNT,
    PROP_FRAMERATE,
+   PROP_FRAMERATE_STRING,
    PROP_UPDATE_DELAY,
    NUM_PROPERTIES
 };
@@ -290,6 +291,14 @@ gtk_fishbowl_get_property (GObject         *object,
       g_value_set_double (value, gtk_fishbowl_get_framerate (fishbowl));
       break;
 
+    case PROP_FRAMERATE_STRING:
+      {
+        char *s = g_strdup_printf ("%.2f", gtk_fishbowl_get_framerate (fishbowl));
+        g_value_set_string (value, s);
+        g_free (s);
+      }
+      break;
+
     case PROP_UPDATE_DELAY:
       g_value_set_int64 (value, gtk_fishbowl_get_update_delay (fishbowl));
       break;
@@ -343,6 +352,13 @@ gtk_fishbowl_class_init (GtkFishbowlClass *klass)
                            0,
                            G_PARAM_READABLE);
 
+  props[PROP_FRAMERATE_STRING] =
+      g_param_spec_string ("framerate-string",
+                           "Framerate as string",
+                           "Framerate as string, with 2 decimals",
+                           NULL,
+                           G_PARAM_READABLE);
+
   props[PROP_UPDATE_DELAY] =
       g_param_spec_int64 ("update-delay",
                           "Update delay",
@@ -491,7 +507,10 @@ gtk_fishbowl_do_update (GtkFishbowl *fishbowl)
 
   n_frames = end_counter - start_counter;
   priv->framerate = ((double) n_frames) * G_USEC_PER_SEC / (end_timestamp - start_timestamp);
+  priv->framerate = ((int)(priv->framerate * 100))/100.0;
+
   g_object_notify_by_pspec (G_OBJECT (fishbowl), props[PROP_FRAMERATE]);
+  g_object_notify_by_pspec (G_OBJECT (fishbowl), props[PROP_FRAMERATE_STRING]);
 
   if (!priv->benchmark)
     return;